import {
  Body,
  Controller,
  Get,
  Inject,
  Post,
  Provide,
  Query,
  ALL,
  Put,
  Param,
  Del,
} from '@midwayjs/decorator';
import { RoomUseRecordsDTO } from '../dto/roomUseRecords';
import { RoomUseRecordsService } from '../service/roomUseRecords';

@Provide()
@Controller('/roomUseRecords')
export class RoomUseRecordsController {
  @Inject()
  roomUseRecordsService: RoomUseRecordsService;

  @Post('/', { description: '新建' })
  async create(@Body(ALL) data: RoomUseRecordsDTO) {
    return await this.roomUseRecordsService.create(data.toEntity());
  }

  @Put('/', { description: '编辑' })
  async edit(@Body(ALL) data: RoomUseRecordsDTO) {
    const roomUseRecords = await this.roomUseRecordsService.getById(data.id);
    // update
    return await this.roomUseRecordsService.edit(roomUseRecords);
  }

  @Del('/:id', { description: '删除' })
  async remove(@Param('id') id: string) {
    const roomUseRecords = await this.roomUseRecordsService.getById(id);
    await this.roomUseRecordsService.remove(roomUseRecords);
  }

  @Get('/:id', { description: '根据id查询' })
  async getById(@Param('id') id: string) {
    return await this.roomUseRecordsService.getById(id);
  }

  @Get('/page', { description: '分页查询' })
  async page(@Query('page') page: number, @Query('size') size: number) {
    return await this.roomUseRecordsService.page(page, size);
  }

  @Get('/list', { description: '查询全部' })
  async list(@Query('roomName') roomName: string, @Query('roomType') roomType: string) {
    const param: Record<string, any> = {};
    roomName && (param.roomName = roomName);
    roomType && (param.roomType = roomType);
    return await this.roomUseRecordsService.list(param);
  }
}